package com.zxy.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zxy.dao.Order;
import com.zxy.dao.OrderMapper;
import com.zxy.dao.OrderStatusConstant;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author : zhangxuyuan
 * @Project: rocketmqtest
 * @Package com.zxy.service
 * @date Date : 2021年05月25日 21:23
 *
 *
 * 延迟订单监听
 */
@Service
@RocketMQMessageListener(topic = "flashsaledelay",consumerGroup = "orderdelaylistener")
public class OrderDelayListener implements RocketMQListener<String> {

    @Autowired
    OrderMapper orderMapper;

    @Override
    public void onMessage(String s) {
        // 将未支付的订单改为已取消
        Order order = new Order(s, OrderStatusConstant.ORDER_CANCEL);
        orderMapper.update(order,new QueryWrapper<Order>().eq("order_id",s)
            .eq("order_status",OrderStatusConstant.ORDER_NOT_PAY));
    }
}
